/**
 * Created by xiaolinzhang on 2017/7/29.
 */

var commService = require("../service/CommService");
var async = require("async");

exports.commInfo = function (req,res,next) {
    async.series({
        commInfo:function (callbk) {
            commService.getCommInfo(req.session.openid,callbk);
        },
        commSum:function (callbk) {
            commService.getCommSum(req.session.openid,callbk);
        }
    },function (err,result) {
        if(!err){
            res.render("comminfo",{title:"我的佣金",commInfo:result.commInfo,commSum:result.commSum});
        }
    });
}

exports.commDetail = function (req,res,next) {
    async.series({
        commDetail:function (callbk) {
            commService.getCommDetail(req.session.openid,1,callbk);
        }
    },function (err,result) {
        if(!err){
            res.render("commdetail",{title:"佣金明细",commDetail:result.commDetail});
        }
    });
}

exports.getCommDetail = function (req,res,next) {
    var sign = req.query.sign;
    async.series({
        commDetail:function (callbk) {
            commService.getCommDetail(req.session.openid,sign,callbk);
        }
    },function (err,result) {
        if(!err){
            res.status(200).end(JSON.stringify(result.commDetail))
        }
    });
}